class Solution 
{
public:
    int maxProfit(vector<int>& prices) 
    {
        if(prices.size()<=1) return 0; 
        int ret=0;
        for(int l=0;l<prices.size();)
        {
            int r=l+1;
            while(r<prices.size()&&prices[r]>=prices[r-1]) r++;
            ret+=prices[r-1]-prices[l];
            l=r;
        }
        return ret;
    }
};